//
//  SongListTableViewController.m
//  Education
//
//  Created by 流风幻雾 on 15/7/16.
//  Copyright (c) 2015年 HUA. All rights reserved.
//

#import "SongListTableViewController.h"
#import "BackImageView.h"
#import "SongListTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "SongListTableViewCellModel.h"
@interface SongListTableViewController ()
@property(strong,nonatomic)NSMutableArray *modelArray;
@end

@implementation SongListTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    BackImageView *backImageView = [[BackImageView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.tableView.backgroundView = backImageView;
    self.headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 80)];
    BackImageView *backImage = [[BackImageView alloc]initWithFrame:self.headView.bounds];
    [self.headView addSubview:backImage];
    self.headView.backgroundColor = [UIColor clearColor];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    UIImageView *leftImageView = [[UIImageView alloc]initWithFrame:CGRectMake(30, 10, 120, 60)];
    leftImageView.image = [UIImage imageNamed:@"air.jpg"];
    [self.headView addSubview:leftImageView];
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(leftImageView.frame.origin.x + leftImageView.frame.size.width + 10, leftImageView.frame.origin.y, 200, 25)];
    titleLabel.text = self.titleName;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    [self.headView addSubview:titleLabel];
    UILabel *countLabel = [[UILabel alloc]initWithFrame:CGRectMake(titleLabel.frame.origin.x, leftImageView.frame.origin.y + leftImageView.frame.size.height - 25, titleLabel.frame.size.width, 25)];
    countLabel.textAlignment = NSTextAlignmentCenter;
    countLabel.text = [NSString stringWithFormat:@"节目数: %@",self.totalCount];
    [self.headView addSubview:countLabel];
    self.tableView.tableHeaderView = self.headView;
    [self.tableView registerClass:[SongListTableViewCell class] forCellReuseIdentifier:@"songListCell"];
    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:self.smallLogo]];
    leftImageView.image = [UIImage imageWithData:data];
    backImage.image = [UIImage imageWithData:data];
    self.modelArray = [NSMutableArray array];
    for (NSDictionary *dic in self.listArray) {
        SongListTableViewCellModel *model = [[SongListTableViewCellModel alloc]init];
        [model setValueWithDictionary:dic];
        [self.modelArray addObject:model];
    }

}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source
//返回行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if(self.listArray.count != 0)
    {
        return self.listArray.count;
    }
    return 10;
}


//返回分区数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SongListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"songListCell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.backgroundColor = [UIColor clearColor];
    [cell setValueWithModel:self.modelArray[indexPath.row]];
    return cell;
}


//返回每行高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 70;
}

@end
